// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#ifndef RECOVERY_IMAGE_HEADER_H_
#define RECOVERY_IMAGE_HEADER_H_

#include <stdint.h>
#include "status/rot_status.h"
#include "flash/flash.h"
#include "common/image_header.h"


/**
 * The magic number marker for a recovery image header.
 */
#define RECOVERY_IMAGE_HEADER_MARKER					0x8a147c29
#define	RECOVERY_IMAGE_HEADER_MAX_LENGTH				1024


/**
 * Interface for a recovery image header that provides information about the image.
 */
struct recovery_image_header {
	struct image_header base;		/**< The base recovery image header instance. */
};


int recovery_image_header_init (struct recovery_image_header *header, struct flash *flash,
	uint32_t addr);
void recovery_image_header_release (struct recovery_image_header *header);

int recovery_image_header_get_version_id (struct recovery_image_header *header, char **version_id);
int recovery_image_header_get_platform_id (struct recovery_image_header *header, char **platform_id);
int recovery_image_header_get_image_length (struct recovery_image_header *header, size_t *length);
int recovery_image_header_get_signature_length (struct recovery_image_header *header,
	size_t *length);
int recovery_image_header_get_length (struct recovery_image_header *header, size_t *length);


#define	RECOVERY_IMAGE_HEADER_ERROR(code)		ROT_ERROR (ROT_MODULE_RECOVERY_IMAGE_HEADER, code)

/**
 * Error codes that can be generated by a recovery image header.
 */
enum {
	RECOVERY_IMAGE_HEADER_INVALID_ARGUMENT = RECOVERY_IMAGE_HEADER_ERROR (0x00),	/**< Input parameter is null or not valid. */
	RECOVERY_IMAGE_HEADER_NO_MEMORY = RECOVERY_IMAGE_HEADER_ERROR (0x01),			/**< Memory allocation failed. */
	RECOVERY_IMAGE_HEADER_BAD_FORMAT_LENGTH = RECOVERY_IMAGE_HEADER_ERROR (0x02),	/**< The header length doesn't match the expected length for the format. */
	RECOVERY_IMAGE_HEADER_BAD_PLATFORM_ID = RECOVERY_IMAGE_HEADER_ERROR (0x03),		/**< An error related to the platform identifier string. */
	RECOVERY_IMAGE_HEADER_BAD_VERSION_ID = RECOVERY_IMAGE_HEADER_ERROR (0x04),		/**< An error related to the version identifier string. */
	RECOVERY_IMAGE_HEADER_BAD_IMAGE_LENGTH = RECOVERY_IMAGE_HEADER_ERROR (0x05),	/**< The recovery image length is invalid. */
};


#endif /* RECOVERY_IMAGE_HEADER_H_ */
